package com.bishe.psy.common;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: L
 * Date: 2024-03-21
 * Time: 18:48
 */
public class AppResult<T> {

    //状态码
    //在yml文件加了default-property-inclusion: NON_NULL 当登录成功返回的data：null，将data不显示，所以就加上JsonInclude
    @JsonInclude(JsonInclude.Include.ALWAYS) // 不论这个字段为任何情况，都参与jsaon序列化
    private int code;
    //描述信息
    @JsonInclude(JsonInclude.Include.ALWAYS) // 不论这个字段为任何情况，都参与jsaon序列化
    private String message;
    //具体数据
    @JsonInclude(JsonInclude.Include.ALWAYS) // 不论这个字段为任何情况，都参与jsaon序列化
    private T data;

    public AppResult(int code, String message) {
        this(code,message,null);
    }

    public AppResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /*
    * 成功
    * */

    public static AppResult success() {
        return new AppResult(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage());
    }

    public static AppResult success(String message) {
        return new AppResult(ResultCode.SUCCESS.getCode(), message);
    }

    public static <T>AppResult<T> success(T data) {
        return new AppResult<T>(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),data);
    }

    public static <T>AppResult<T> success(String message,T data) {
        return new AppResult<T>(ResultCode.SUCCESS.getCode(), message,data);
    }

    public static <T>AppResult<T> success_like() {
        return new AppResult<T>(ResultCode.LIKE_SUCCESS.getCode(), ResultCode.LIKE_SUCCESS.getMessage());
    }

    public static <T>AppResult<T> success_no_like() {
        return new AppResult<T>(ResultCode.NO_LIKE_SUCCESS.getCode(), ResultCode.NO_LIKE_SUCCESS.getMessage());
    }


    /*
    * 失败
    * */
    public static AppResult failed() {
        return new AppResult(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage());
    }

    public static AppResult failed(String message) {
        return new AppResult(ResultCode.FAILED.getCode(), message);
    }

    public static AppResult failed(ResultCode resultCode) {
        return new AppResult(resultCode.getCode(),resultCode.getMessage());
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


}
